#ifndef file_file_c_h
#define file_file_c_h

#include <cstdio>
#include <common/include/memory.h>
#include "../include/file.h"

using cmn::mem;
using cmn::byte;
using cmn::kbyte;
using cmn::dword;
using cmn::kcstr;
using cmn::kcwstr;
using io::file;

class file_base
{
public:
	inline			~file_base()					{ close(); }

	bool			open(kcstr _filename, kcstr _mode);

	bool			open(kcwstr _filename, kcwstr _mode);

	void			close();

	inline bool		is_open() const					{ return m_file_ptr != nullptr; }

	bool			seek(dword _offset, file::seek_dir _dir);

	inline dword	tell() const					{ return ftell(m_file_ptr); }

	inline dword	length() const					{ return m_length; }

	inline kcstr	name() const					{ return (kcstr)m_file_name; }

	inline dword	read(void* _mem, dword _size)	{ return fread(_mem, 1, _size, m_file_ptr); }

	dword			write(const void* _mem, dword _size);

private:
	FILE*	m_file_ptr = nullptr;
	dword	m_length = 0;
	mem		m_file_name;
};

#endif
